import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { ProductComponent } from './product/product.component';
import { ProductService } from './shared/product.service';
import { LoggerService } from './shared/logger.service';
import { AnotherProductService } from './shared/another-product.service';

@NgModule({
  declarations: [
    AppComponent,
    ProductComponent,
  ],
  imports: [
    BrowserModule
  ],
  //providers: [ProductService],
  providers: [{
    provide: ProductService,
    useFactory: (logger, env,cfg) => {
      if (cfg.env) {
        var service = new ProductService(logger);
        return service;
      } else {
        var service = new AnotherProductService(logger);
        return service;
      }
    },
    deps: [LoggerService, 'IS_DEV_ENV', 'APP_CONFIG']
  }, LoggerService,
    { provide: 'IS_DEV_ENV', useValue: true },
    { provide: 'APP_CONFIG', useValue: { env: Math.random() < 0.5 } }],
  bootstrap: [AppComponent]
})
export class AppModule { }
